import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout'
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/home')
      },
      {
        path: 'category/:id',
        component: () => import('@/views/category')
      },
      {
        path: 'category/sub/:id',
        component: () => import('@/views/category/sub.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login') // 路由懒加载
  },
  {
    path: '/login/callback',
    component: () => import('@/views/login/callback')
  }
]

const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则，写法和之前一样
  routes,
  // 切换路由会跳转到最上面
  scrollBehavior() {
    return { left: 0, top: 0 }
  }
})

export default router
